using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using DataTreeLib;
using System.Drawing;

namespace DocToolTipLib.Mappers
{
  public class DocToolTipTreeNodeMapper : ITreeNodeMapper
  {
    private ContextMenuStrip _cntxMnuStrip;

    #region ITreeNodeMapper Members
    public DocToolTipTreeNodeMapper()
    {
      _cntxMnuStrip = null;

    }

    public DocToolTipTreeNodeMapper(ContextMenuStrip cntxMnuStrip)
    {
      _cntxMnuStrip = cntxMnuStrip;

    }

    void mnuItem_Click(object sender, EventArgs e)
    {
      
    }


    public System.Windows.Forms.ContextMenuStrip GetContextMenuStrip(TreeNode treeNode)
    {
      return _cntxMnuStrip;
    }

    public object GetNodeInfo(System.Windows.Forms.TreeNode treeNode)
    {
      return treeNode.Tag;
    }

    public void UpdateNode(object dataNode, System.Windows.Forms.TreeNode treeNode)
    {
      DTreeNode<DocToolTip> dNode = dataNode as DTreeNode<DocToolTip>;
      treeNode.Text = dNode.Value.ControlName;
      treeNode.Tag = dNode;
      
      treeNode.Checked = dNode.Value.Visible;
      ImageList imageList = treeNode.TreeView.ImageList;

      string strControlName = "Control_" + dNode.Value.ControlType.Name;
      int iIndex = -1;

      if(imageList.Images.ContainsKey(strControlName))
      {
        iIndex = imageList.Images.IndexOfKey(strControlName);
      }

      treeNode.ImageIndex = iIndex;
      treeNode.SelectedImageIndex = iIndex;
    }

    #endregion
  }
}
